package com.zjsy.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import com.zjsy.dao.MainNewsDao;
import com.zjsy.page.PageBean;
import com.zjsy.page.PageConstants;
import com.zjsy.po.MainNews;
import com.zjsy.po.MainNewsList;
import com.zjsy.po.MainNewsModule;
import com.zjsy.service.MainNewsService;

@Service
@Transactional
public class MainNewsServiceImpl implements MainNewsService  {
	
	@Autowired
	private MainNewsDao mainNewsDao;

	@Override
	public void addNewsModule(MainNewsModule newsmodule) {
		
		mainNewsDao.addNewsModule(newsmodule);
		
	}

	@Override
	public List<MainNewsModule> findNewsModule(String kind) {
		// TODO Auto-generated method stub
		return mainNewsDao.findNewsMoudle(kind);
	}



	@Override
	public void updateNewByid(MainNewsModule newsmodule) {
		
		 mainNewsDao.updateNewByid(newsmodule);
	}

	@Override
	public MainNewsModule findNewsModuleById(String id) {
		// TODO Auto-generated method stub
		return mainNewsDao.findNewsMoudleById(id);
	}

	@Override
	public void addNews(MainNews mainnews) {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
		mainnews.setUptime(df.format(new Date()));// new Date()为获取当前系统时间
		mainNewsDao.addNews(mainnews);
	}

	@Override
	public List<MainNewsList> findMainNews() {
		// TODO Auto-generated method stub
		return mainNewsDao.findMainNews();
	}

	@Override
	public MainNews findMainNewsById(String id) {
		
		return mainNewsDao.findMainNewsById(id);
		
	}

	@Override
	public void updateNewsByid(MainNews news) {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
		
		news.setUptime(df.format(new Date()));// new Date()为获取当前系统时间
		mainNewsDao.updateNewsByid(news);
		
	}

	@Override
	public void deleteNewsByid(String id) {
		mainNewsDao.deleteNewsByid(id);
		
	}

	@Override
	public PageBean<MainNewsList> findMainNewsByPage(int pc) {
		//先查询模糊查询得到的所有数据
		//得到ps
		int ps = PageConstants.BOOK_PAGE_SIZE;
		int min = (pc-1)*ps;
		int max = ps;
		//得到beanList
		List<MainNewsList> beanLsit = mainNewsDao.findMainNewsByPage(min, max);
		//得到所有的记录数
		int tr = mainNewsDao.findMainNews().size();
		PageBean<MainNewsList> pb = new PageBean<>();
		pb.setBeanList(beanLsit);
		pb.setPc(pc);
		pb.setPs(ps);
		pb.setTr(tr);
		return pb;
	}

	@Override
	public PageBean<MainNewsList> findMainNewsByDetail(String firstClassify, String secondClassify, int pc) {
		
		int ps = PageConstants.BOOK_PAGE_SIZE;
		int min = (pc-1)*ps;
		int max = ps;
		//得到beanList
		List<MainNewsList> beanLsit = mainNewsDao.findMainNewsByDetail(firstClassify, secondClassify, min, max);
		//得到所有的记录数
		int tr = mainNewsDao.findMainNewsByDetails(firstClassify, secondClassify).size();
		PageBean<MainNewsList> pb = new PageBean<>();
		pb.setBeanList(beanLsit);
		pb.setPc(pc);
		pb.setPs(ps);
		pb.setTr(tr);
		return pb;
	}

	@Override
	public List<MainNewsList> findShufflingNews() {
	
		return mainNewsDao.findShufflingNews();
	}

	@Override
	public void updateShufllingNewsByid(MainNews news) {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 设置日期格式

		news.setUptime(df.format(new Date()));// new Date()为获取当前系统时间

		mainNewsDao.updateShufllingNewsByid(news);
		
	}

	@Override
	public MainNews findShufflingNewsById(String id) {
	
		return mainNewsDao.findShufflingNewsById(id);
	}

	
	
	

}
